<template>
	<view class="yhqBg flex">
		<view class="">
			<view class="yhqBgMoney font-72 font-weight f-t lh-56"><text
					class="font-32">￥</text>{{Number(item.money)||''}}</view>
			<view class="" v-if="Number(item.at_least)">满{{item.at_least}}可用</view>
			<view class="" v-else>无门槛优惠券</view>
		</view>
		<view class="flex_b m-l-20 w-450">
			<view class="w-322">
				<view class="font-32 font-weight hiddenSty">{{item.coupon_name}}</view>
				<view class="font-20 grey">{{item.end_time_text}}</view>
			</view>
			<!-- <view class="submitBtn">去使用</view> -->
			<block v-if="type=='useYhq'">
				<view class="submitBtn" @click="useYhqFn(item)">确认使用</view>
			</block>
			<block v-if="type=='lqYhq'">
				<view class="submitBtn"  @click="lingQuFn(item)">领取</view>
			</block>
			<block v-if="type=='myYhq'">
				<view class="submitBtn"  @click="goUse" v-if="typeName=='未使用'">{{typeName||''}}</view>
				<view class="submitBtn"  style="background-color: #cccccc;" v-else>{{typeName||''}}</view>
			</block>
		</view>

		<uv-toast ref="uToast"></uv-toast>

	</view>
</template>

<script>
	export default {
		name: "yhqItem",
		data() {
			return {

			};
		},
		props: ['item', 'type','typeName'],
		methods: {
			goUse() {
				// 去使用 
				if(this.typeName=='未使用') {
					uni.switchTab({
						url:'/pages/index/index'
					})
				}else {
					
				}
			},
			useYhqFn(item) {
				// 使用
				uni.$emit('yhq', item)
				uni.navigateBack({
					delta: 1
				})
			},

			lingQuFn(item) {
				this.$api.sendRequest({
					url: '/api/coupon/receive',
					data: {
						id: item.id
					},
					success: res => {
						if (res.code == 1) {
							this.$refs.uToast.show({
								type: 'default',
								message: '领取成功',
							})
							this.$emit('getCouponLists')
						} else {
							this.$refs.uToast.show({
								type: 'default',
								message: res.msg,
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.yhqBg {
		width: 650rpx;
		height: 156rpx;
		opacity: 1;
		border-radius: 16rpx;
		background: rgba(255, 246, 246, 1);
		margin: 25rpx auto;
		padding: 0 20rpx;

		.yhqBgMoney {
			width: 180rpx;
			border-right: 1rpx dashed #e1c6ca;
			height: 100%;
		}

		.submitBtn {
			width: 92rpx;
			height: 40rpx;
			border-radius: 20rpx;
			background-color: #e5632b;
			font-size: 20rpx;
			text-align: center;
			color: #fff;
			line-height: 40rpx;
		}
	}
</style>